<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue v-for 循环遍历</title>
    <style>
        div {
            padding: 10px;
            border: 1px solid green;
        }

        h2 {
            padding: 10px;
            border: 1px solid rgb(228, 95, 210);
        }
    </style>
</head>

<body>
    <div id="app">
        <h2>text here：
            <span>{{message}}</span>
        </h2>
        <!-- 遍历数组 -->
        <h2>遍历数组</h2>
        <ul>
            <li v-for="item in names">{{item}}</li>
        </ul>
        <br>

        <!-- 遍历数组，带索引，item对应元素，index对应下标 -->
        <ul>
            <li v-for="(item,index) in names">{{index+1}}.{{item}}</li>
        </ul>
        <br>

        <h2>遍历对象</h2>
        <!-- 遍历对象 -->
        <ul>
            <li v-for="(value,key) in info">{{key}}: {{value}}</li>
        </ul>
        <br>
        <ul>
            <!-- 这种方式很少用 -->
            <li v-for="(value,key,index) in info">{{index}}.{{key}}: {{value}}</li>
        </ul>
        <br>

        <h2>遍历数字</h2>
        <!-- 遍历数字 -->
        <ul>
            <li v-for="index in 6">{{index}}</li>
        </ul>

        <button v-on:click='action'>点击</button>
    </div>

    <script src="js/vue.js"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data: {
                message: 'this is a vue demo!',
                names: ['apple', 'pear', 'banana', 'orange'],
                info: {
                    name: 'Hua',
                    age: 18,
                    height: 1.88
                }
            },
            computed: {

            },
            methods: {
                action: function () {
                    this.message = 'hello!'
                }
            }
        });
    </script>
</body>

</html>
